import java.util.LinkedList;
import java.util.Scanner;

/*
 * Test class for ConfigurePresentation
 */
public class Test {

      static String email;
      static String user;
      static String pass;

	
	private static LinkedList<PresentationInstance> decks;
	private static PresentationInstance present;
	private static Log log;
    
	public static void main(String[] args) {
		log = new Log(1, "log.txt", "Log file about PresentationConfigurer",
				"");
		
		decks = new LinkedList<PresentationInstance>();
        PresentationInstance one = new PresentationInstance(250,
                "Programming in C++!","Multiple inheritance",1365,
                "Becky Williams",4,8,32,40);
        log.writeInLog("Presentation " + one.toString()+ " created");
        
        PresentationInstance two = new PresentationInstance(314,
                "Programming in Java!","Introduction",2145,
                "Rob Jameson",3,12,25,25);
        log.writeInLog("Presentation " + two.toString()+ " created");
        
        // make slides for presentation 1
        SlideNumber sOne = new SlideNumber(Difficulty.EASY, Length.SHORT, 
        		Capitalization.NORMAL, 1, Slides.s1);
        SlideNumber sTwo = new SlideNumber(Difficulty.EASY, Length.LONG,
        		Capitalization.NORMAL, 2, Slides.s2);
        SlideNumber sThree = new SlideNumber(Difficulty.MODERATE, Length.SHORT,
        		Capitalization.NORMAL, 3, Slides.s3);
        SlideNumber sFour = new SlideNumber(Difficulty.MODERATE, Length.LONG,
        		Capitalization.NORMAL, 4, Slides.s4);
        SlideNumber sFive = new SlideNumber(Difficulty.PRO, Length.LONG,
        		Capitalization.NORMAL, 5, Slides.s5);
        SlideNumber sSix = new SlideNumber(Difficulty.PRO, Length.SHORT,
        		Capitalization.NORMAL, 6, Slides.s6);
        
        // add the slides to presentation 1
        one.addSlide(sOne);
        one.addSlide(sTwo);
        one.addSlide(sThree);
        one.addSlide(sFour);
        one.addSlide(sFive);
        one.addSlide(sSix);
        
        // make slides for presentation 2
        SlideNumber jOne = new SlideNumber(Difficulty.EASY, Length.SHORT, 
        		Capitalization.NORMAL, 1, Slides.j1);
        SlideNumber jTwo = new SlideNumber(Difficulty.EASY, Length.LONG,
        		Capitalization.NORMAL, 2, Slides.j2);
        SlideNumber jThree = new SlideNumber(Difficulty.MODERATE, Length.SHORT,
        		Capitalization.NORMAL, 3, Slides.j3);
        SlideNumber jFour = new SlideNumber(Difficulty.PRO, Length.LONG,
        		Capitalization.NORMAL, 4, Slides.j4);
        SlideNumber jFive = new SlideNumber(Difficulty.MODERATE, Length.LONG,
        		Capitalization.NORMAL, 5, Slides.j5);
        SlideNumber jSix = new SlideNumber(Difficulty.PRO, Length.SHORT,
        		Capitalization.NORMAL, 6, Slides.j6);
        
        // add slides to presentation 2
        two.addSlide(jOne);
        two.addSlide(jTwo);
        two.addSlide(jThree);
        two.addSlide(jFour);
        two.addSlide(jFive);
        two.addSlide(jSix);
        
        decks.add(one);
        decks.add(two);
        
        // sends welcome messages
        String login = "Hello and welcome to Presentaion Configurer v 1.0!\n" +
        		"Please login in our System to use the program:";
        String welcome="Please choose which presentation to configure:";
        System.out.println(login+"\n ------------------------------------\n"
                + "Username:");
        // read input to select the correct presentation
        Scanner scan = new Scanner(System.in);

        while(true){
			user = scan.nextLine();
			try{

				if (user.length()>0){
					log.writeInLog("User with name "+user+" logged in.");
					break;
                }
			}
			catch (NumberFormatException e){}
			System.out.println("Wrong username. Try again");
		}
        System.out.println("\n Email:");


        while(true){
			email = scan.nextLine();
			try{

				if (email.length()>0){
					log.writeInLog(user+" entered "+email+" as their email address.");
					break;
				}
			}
			catch (NumberFormatException e){}
			System.out.println("Wrong username. Try again");
            }
        System.out.println("\n Password:");

        while(true){
			pass = scan.nextLine();
			try{

				if (pass.length()>0){
					log.writeInLog(user+" entered a password");
					break;
				}
			}
			catch (NumberFormatException e){}
			System.out.println("Wrong username. Try again");
            }
        User us=new User();

        us.setEmail(email);
        us.setUserName(user);

        us.online();


        System.out.println(welcome);
        for(int i = 1; i <= decks.size(); i++){
        	String str = i + ": " + decks.get(i-1).getTitle();
        	System.out.println(str);
        }
        
        
        int chosen = 0;
		while(true){
			String line = scan.nextLine();
			try{
				chosen = Integer.parseInt(line);
				if (chosen > 0 && chosen <= decks.size())
					break;
				else throw new InvalidOptionException();
			}
			catch (NumberFormatException e){}
			catch (InvalidOptionException e){}
			System.out.println("Wrong number of presentation. Try again");
		}
		
		// assign the correct presentation
		present = decks.get(chosen-1);
		log.writeInLog("Presentation number "+chosen+ " chosen.");
		System.out.println("-----------------------------------------------\n");
		present.showInfo();
		System.out.println("-----------------------------------------------\n");
		
		// choose level of difficulty
		System.out.println("Choose level of difficulty:");
		System.out.println(present.listDifficulties());
		while(true){
			String line = scan.nextLine();
			try{
				chosen = Integer.parseInt(line);
				if(present.isDifficultyValid(chosen))
					break;
				else throw new InvalidOptionException();
			}
			catch (NumberFormatException e){}
			catch (InvalidOptionException e){}
			System.out.println("Wrong level of difficulty chosen. Try again");
		}
		
		// set the level of difficulty
		present.setDifficulty(chosen);
		log.writeInLog("Level of difficuty for presentation "+chosen+" was chosen.");
		System.out.println("You selected level of difficulty: "+present.getLevelOfDifficulty());
		System.out.println("-----------------------------------------------\n");
		
		// choose length of presentation
		System.out.println("Choose length of presentation:");
		System.out.println(present.listLengths());
		while(true){
			String line = scan.nextLine();
			try{
				chosen = Integer.parseInt(line);
				if(present.isLengthValid(chosen))
					break;
				else throw new InvalidOptionException();
			}
			catch (NumberFormatException e){}
			catch (InvalidOptionException e){}
			System.out.println("Wrong length of presentation chosen. Try again");
		}
		
		// set the length of the presentation
		present.setLength(chosen);
		log.writeInLog("Length of presentation "+chosen+" was chosen.");
		System.out.println("You selected length of presentation: "+present.getLength());
		System.out.println("-----------------------------------------------\n");
		
		// choose capitalization
		System.out.println("Choose capitalization:");
		System.out.println(present.listCapitalization());
		while(true){
			String line = scan.nextLine();
			try{
				chosen = Integer.parseInt(line);
				if(present.isCapitalizationValid(chosen))
					break;
				else throw new InvalidOptionException();
			}
			catch (NumberFormatException e){}
			catch (InvalidOptionException e){}
			System.out.println("Wrong capitalization chosen. Try again");
		}
		
		// set the capitalization
		present.setCapitalization(chosen);
		log.writeInLog("Capitalization of type "+chosen+" was selected.");
		System.out.println("You selected capitalization: "+present.getCapitalization());
		System.out.println("-----------------------------------------------\n");
		
		// ask for presentation preview
		System.out.println("Would you like to see the presentation now?");
		System.out.println("1 YES");
		System.out.println("2 NO (The program will then exit)");
		while(true){
			String line = scan.nextLine();
			try {
				chosen = Integer.parseInt(line);
				if (chosen == 1 || chosen == 2)
					break;
				else throw new InvalidOptionException();
			}
			catch (NumberFormatException e){}
			catch (InvalidOptionException e){}
			System.out.println("Wrong option chosen. Try again");
		}
		
		// close the scanner before the program quits
		
		
		if(chosen == 1){
			present.displayPresentation();
			log.writeInLog("The presentation has been displayed");
		}
		
		System.out.println("This is the end of the presentation.If you \n"
                        + "want to logout \n#Press 1");
        while(true){
			String button = scan.nextLine();
			try{
				chosen = Integer.parseInt(button);
				if(chosen==1){
					us.offline();
					log.writeInLog(user+" logged out.");
                    break;
                }
				else throw new InvalidOptionException();

			}
			catch(NumberFormatException e){}
			catch (InvalidOptionException e){}
            System.out.println("Press 1 to logout.");
        }


        scan.close();
		log.writeInLog("The program was shut down.");
    }


}
